
'''
def call_filter(call_stack, module_name, class_name, func_name, full_name):
    L = ['core', 'ui']
    for i in L:
        if module_name.startswith(i):
            return True
    return False

import pycallgraph
pycallgraph.start_trace(filter_func=call_filter)
'''

import api
ni = api.API()
ni.initialize()

#pycallgraph.make_dot_graph('test.png')


from core import cmds
from core.base import Expression

view_group = ni.Group(name="Views")
pipeline_group = ni.Group(name="Pipelines")

graph = ni.Graph(name="Graph View", parent=view_group)
plugin_editor = ni.PluginEditor(name="Plugin Editor", parent=view_group)
node_view = ni.NodeView(name="Node View", parent=view_group)
node_view.data = ["types(ServerComponent)", "types(Util)"]
data_editor = ni.DataEditorView(name="Data Editor", parent=view_group)
pipe = ni.Pipeline(name="Standard Pipeline", parent=pipeline_group, override=True)
db_view = ni.DBView(name="Database View", parent=view_group, override=True)

user_view = ni.ListView(name="User View", override=True)

user_group = ni.Group(name="Users")
user1=ni.User(name="Mikkel", parent=user_group, override=True)
user2=ni.User(name="Sunit", parent=user_group, override=True)
user3=ni.User(name="Nicolai", parent=user_group, override=True)

tasks = ni.Group()

for i in range(3):
    ni.Task(parent=tasks, worker=user1)
for i in range(3):
    ni.Task(parent=tasks, worker=user2)
for i in range(3):
    ni.Task(parent=tasks, worker=user3)


user_view.data = Expression("ls(User)")
#user_view.group = "item.parent"
user_view.columns = ["item.parent"]


def create_test_nodes():
    production = ni.Production(name="HydraLab", path="//SCYLLA/repository/projects")
    
    projects = [('Machine', 'machine/MA'),
                ('Aalborg', 'aalborg/AB'),
                ('Aquapurin', 'aquaporin/AP')]
    for name, path in projects:
        prj = ni.Project(name=name, parent=production, path=Expression("self.parent.path + '/" + path + "'"))
        shot_view = ni.ListView(name=name+" Shots", parent=prj)
        shot_view.data = Expression("ls(Shot, parent='"+name+"')")
        shot_view.group = "item.parent"
        for seq in range(3):
            s = ni.Sequence(name="Seq_"+str(seq), parent=prj)
            for shot in range(3):
                sh = ni.Shot(name="Shot_"+str(shot), parent=s)
    
create_test_nodes()

script_editor = ni.ScriptEditor()
rel_graph = ni.RelationalGraph()

ni.app.main_window.add_view(node_view, "left")
#ni.app.main_window.add_view(graph, "bottom")
ni.app.main_window.add_view(plugin_editor, "bottom")
ni.app.main_window.add_view(rel_graph, "center")
ni.app.main_window.add_view(data_editor, "right", tab=False)
ni.app.main_window.add_view(db_view, "left")


ni.app.run_ui()